package com.zhuanzhuan.dao.impl;
import com.zhuanzhuan.dao.BaseDao;
import com.zhuanzhuan.dao.TypeDao;
import com.zhuanzhuan.entity.Type;
import com.zhuanzhuan.vo.GoodsDetail;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TypeDaoMySQLImpl extends BaseDao implements TypeDao {

    //获取好物类型列表
    @Override
    public List<Type> getTypeList() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        List<Type> types = new ArrayList<Type>();

        conn = getConnection();
        try {
            //构造PreparedStatement对象
            String sql = "SELECT * from type;";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            //验证用户名和密码
            while(rs.next()){
                Type type= new Type();
                type.setId(rs.getInt("id"));
                type.setName(rs.getString("name"));
                types.add(type);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //关闭数据库连接
            closeAll(conn, pstmt, rs);
        }
        return types;
    }
}
